using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace TestCases.UI.SettingsUI
{	

	/// <summary>
	/// Defines the DriveTypes used for Win32_LogicalDisk<seealso cref="RcmTreeViewExplorer"/>.This enumeration can be treated as a bit field; that is, a set of flags.
	/// </summary>
	[Flags]
	public enum DriveTypes
	{
		/// <summary>
		/// NoRootDirectory
		/// </summary>
		NoRootDirectory = 0x0001,
		/// <summary>
		/// Drive has removable media. This includes all floppy drives and many other varieties of storage devices.
		/// </summary>
		RemovableDisk = 0x0002,
		/// <summary>
		/// Drive has fixed (nonremovable) media. This includes all hard drives, including hard drives that are removable.
		/// </summary>
		LocalDisk = 0x0004,
		/// <summary>
		/// Network drives. This includes drives shared anywhere on a network.
		/// </summary>
		NetworkDrive = 0x0010,
		/// <summary>
		/// Drive is a CD-ROM. No distinction is made between read-only and read/write CD-ROM drives.
		/// </summary>
		CompactDisc= 0x0020,
		/// <summary>
		/// Drive is a block of Random Access Memory (RAM) on the local computer that behaves like a disk drive.
		/// </summary>
		RAMDisk= 0x0040
	}	
	/// <summary>
	/// Demo settings class with some data types.
	/// </summary>
	[Serializable]
	public class Settings : ICloneable
	{
		#region attributes
		DriveTypes anchorStyles;
		string s = "";
		bool b = false;
		int i = 0;
		DateTime dt = DateTime.Now;
		DockStyle uriPartial;
		decimal dec;
		Keys keys;
		Color color;
		#endregion

		public Settings()
		{			
			//
			// TODO: Add constructor logic here
			//
		}		
		[Category("Extended\\Color"), Description("Color")]
		public Color Color
		{
			get
			{
				return color;
			}
			set
			{
				color = value;
			}
		}
		[Category("Extended\\Flags Enum"), Description("Flags Enum")]
		public Keys Keys
		{
			get
			{
				return keys;
			}
			set
			{
				keys = value;
			}
		}
		[Category("Extended\\Flags Enum"), Description("Flags Enum")]
		public DriveTypes AnchorStyles
		{
			get
			{
				return anchorStyles;
			}
			set
			{
				anchorStyles = value;
				Console.Write("anchorStyles has changed");
			}
		}
		public string AnchorStylesValidating(System.Windows.Forms.AnchorStyles newValue)
		{
			//if((newValue & System.Windows.Forms.AnchorStyles.None) == System.Windows.Forms.AnchorStyles.None) return "System.Windows.Forms.AnchorStyles.None is not valid!";
			return string.Empty;
		}
		[Category("DataTypes\\String"),DescriptionAttribute("String")]
		public string String
		{
			get
			{
				return s;
			}
			set
			{
				s = value;
				Console.Write("string has changed");
			}
		}
        //public string StringValidating(string newValue)
        //{	
        //    if(newValue.Length<2) return string.Empty;
        //    // validating failed, return error message
        //    return "string.Length<2";			
        //}
		[Category("DataTypes\\Boolean"),DescriptionAttribute("Boolean")]
		public bool Boolean
		{
			get
			{
				return b;
			}
			set
			{
				b = value;
				Console.Write("boolean has changed");
			}
		}
		public string BooleanValidating(bool newValue)
		{
			return string.Empty;
		}
		[Category("DataTypes\\Int"),DescriptionAttribute("int")]
		public int Int
		{
			get
			{
				return i;
			}
			set
			{
				i = value;
				Console.Write("int has changed");
			}
		}
		public string IntValidating(int newValue)
		{
			if(newValue > 12) return "Zahl zu gross";
			return string.Empty;
		}
		[Category("DataTypes\\DateTime"),DescriptionAttribute("DateTime")]
		public DateTime DateTime
		{
			get
			{
				return dt;
			}
			set
			{
				dt = value;
				Console.Write("datetime has changed");
			}
		}
		public string DateTimeValidating(DateTime newValue)
		{			
			return string.Empty;
		}
		
		[Category("DataTypes\\Enum"),DescriptionAttribute("Enum")]
		public DockStyle DockStyle
		{
			get
			{
				return uriPartial;
			}
			set
			{
				uriPartial = value;
			}
		}
		public string DockStyleValidating(DockStyle newValue)
		{
			return (newValue!= DockStyle.None) ? "" : "None is not a valid item";
		}
		[Category("DataTypes\\Decimal"),DescriptionAttribute("Decimal")]
		public decimal Decimal
		{
			get
			{
				return dec;
			}
			set
			{
				dec = value;
			}
		}

		#region ICloneable Members

		public object Clone()
		{
			// create new settings class and copy all public properties values to clone
			Settings s = new Settings();
			foreach(System.Reflection.PropertyInfo pi in  s.GetType().GetProperties())
			{
				pi.SetValue(s,this.GetType().GetProperty(pi.Name).GetValue(this,null),null);
			}
			return s;
		}

		#endregion
	}
}
